package com.zhangyx.crawler.qixin;

import com.zhangyx.crawler.comm.ThreadUtil;
import com.zhangyx.crawler.core.browser.BrowserUtil;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Qixin {

    public static void checkLogin(ChromeDriver driver){
        String curl = driver.getCurrentUrl();
        if (curl.contains("www.qixin.com/auth/login")) {
            WebElement user = driver.findElementByCssSelector("#s1-0\\[0\\]-0\\[0\\]-account");
            user.sendKeys("18829343578");
            WebElement password = driver.findElementByCssSelector("#s1-0\\[0\\]-0\\[0\\]-password");
            password.sendKeys("ZYX@4502396");
            WebElement btn = driver.findElementByCssSelector("#s1-0\\[0\\]-0\\[0\\] > div > div > div > div:nth-child(4) > a");
            btn.click();
        }
    }

    public static void checkCaptcha(ChromeDriver driver) {
        try {
            WebElement captcha = driver.findElementByCssSelector("#s2-captcha-gtCaptcha");
            WebElement geetestPanel = driver.findElementByCssSelector("div.geetest_panel.geetest_wind");
            WebElement wordCaptcha = driver.findElementByCssSelector(".geetest_widget");
            WebElement wordCaptchaSubmit = driver.findElementByCssSelector("body > div.geetest_panel.geetest_wind > div.geetest_panel_box > div.geetest_panel_next > div > div.geetest_widget > div.geetest_panel > a > div");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args){
        ChromeDriver driver = BrowserUtil.createChromeDriver();
        try {
            driver.get("https://www.qixin.com/");
                WebElement search = driver.findElementByCssSelector("#s0-c1-search-btn-key");
            search.sendKeys("小米科技");
            ThreadUtil.sleepMills(1000*1);
            WebElement searchBtn = driver.findElementByCssSelector("#s0-c1-search-btn > i");
            searchBtn.click();
            checkLogin(driver);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ThreadUtil.sleepMills(1000*30);
        driver.quit();
    }

}
